<?php

//智能后台渲染html
namespace ui;
class Component {
    /**
     * row  开合
     * @return string  $doc
     */
    static public function row($config = []){
        if($config=='/'){
            return "</div>";
        }
        $doc = "<div class=\"layui-row layui-col-space15\">";
        return $doc;
    }
    /**
     * 栅格布局 开合
     * @param int $pc  桌面下的栅格占比
     * @param int $pad pad下的栅格占比
     * @param int $mobile  移动端下的栅格占比
     * @return string  $doc
     */
    static public function col($config = []){
        if($config=='/'){
            return "</div>";
        }
        $default_config = [
            'pc' => 12,
            'pad' => 12,
            'mobile' => 12
        ];
        $config = $config + $default_config;
        $doc = "<div class=\"";
        $doc .= "layui-col-xs{$config['mobile']} ";//移动
        $doc .= "layui-col-sm{$config['pad']} ";//平板
        $doc .= "layui-col-md{$config['pc']}\">";//PC
        return $doc;
    }

    /**
     * form表单 开合
     * @param int $id 唯一标识
     * @param array $action ['create'] ['update',15]
     * @param int $mobile  移动端下的栅格占比
     * @return string  $doc
     */

    static public function tableForm($config = []){
        if($config=='/'){
            return "</form>";
        }
        $default_config = [
            'id'=>'',
            'action'=>['read',''],
            'method'=>'post',
        ];
        $config = $config + $default_config;
        $action = '';
        if(is_array($config['action'])){
            $id = '';
            $actionLetter = ucfirst($config['action'][0]);
            if(isset($config['action'][1])){
                $id = $config['action'][1];
            }
            $action = 'table'. $actionLetter .'?id='.$id;
        }

        $doc = "<form class=\"layui-form auto-iframe iframe-table\"
                data-id=\"{$config['id']}\" action=\"$action\" 
                method=\"{$config['method']}\">";
        return $doc;
    }
    /**
     * 提示icon
     * @param string $msg  桌面下的栅格占比
     * @return string  $doc
     */
    static public function tip($config = []){
        $default_config = [
            'msg'=>'提示语'
        ];
        $config = $config + $default_config;
        $doc = "<i class=\"layui-icon layui-icon-tips\" lay-tips=\"{$config['msg']}\"></i>";
        return $doc;
    }
    /**
     * 普通盒子
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $right 头部右侧内容
     * @return string  $doc
     */
    static public function card($config = []){
        if($config=='/'){
            return "</div></div></div>";
        }
        $default_config = [
            'id'=>'',
            'height'=>'',
            'title'=>'标题',
            'right'=>''
        ];
        $config = $config + $default_config;
        $doc =
            "<div class=\"layui-card\" id=\"{$config['id']}\">
         <div class=\"layui-card-header\">{$config['title']}</div>
         <div class=''>
         <div class=\"layui-card-body\">
            <div class=\"card-header-right\">
                  {$config['right']}
            </div>"
        ;
        return $doc;
    }
    /**
     * 栏目盒子
     * @param string $id 唯一id
     * @param array $title 标题
     * @param string $right 头部右侧内容
     * @return string  $doc
     */
    static public function navCard($config=[]){
        if($config=='/'){
            return "</ul></div></div>";
        }
        $default_config = [
            'id'=>'',
            'title'=>['栏目1','栏目2'],
            'right'=>''
        ];
        $config = $config + $default_config;
        $doc ="
        <div class=\"layui-card\" id=\"{$config['id']}\">
            <div class=\"layui-card-header\">
                <div class=\"layui-tab layui-tab-brief\">
                <ul class=\"layui-tab-title\">";
        if(is_array($config['title'])){
            foreach ($config['title'] as $k=>$v){
                if($k==0){
                    $doc .= "<li class='layui-this'>{$v}</li>";
                }
                else{
                    $doc .= "<li>{$v}</li>";
                }
            }
        }
        $doc .= "</ul></div></div><div class=\"layui-card-body\"><div class=\"card-header-right\">{$config['right']}</div><ul>";
        return $doc;
    }
    /**
     * banner盒子
     * @param string $id 唯一id
     * @param array $title 标题
     * @param string $right 头部右侧内容
     * @return string  $doc
     */
    static public function bannerCard($config=[]){
        if($config=='/'){
            return "</ul></div></div>";
        }
        $default_config = [
            'id'=>'',
            'title'=>['标题1','标题2','标题3'],
            'speed'=>0
        ];
        $config = $config + $default_config;
        $doc = "<div class=\"banner-card layui-card\" id=\"{$config['id']}\"><div class=\"layui-card-header\"><ul>";
        if(is_array($config['title'])){
            foreach ($config['title'] as $k=>$v){
                if($k==0){
                    $doc .= "<li class='layui-show'>{$v}</li>";
                }
                else{
                    $doc .= "<li>{$v}</li>";
                }
            }
        }
        if($config['speed']){
            $doc .="</ul><div class=\"layui-carousel-ind layui-auto\" data-speed=\"{$config['speed']}\"><ul>";
        }
        else{
            $doc .="</ul><div class=\"layui-carousel-ind\"><ul>";
        }
        if(is_array($config['title'])){
            foreach ($config['title'] as $k=>$v){
                if($k==0){
                    $doc .= "<li class='layui-this'></li>";
                }
                else{
                    $doc .= "<li></li>";
                }
            }
        }
        $doc .= "</ul></div></div><div class=\"layui-card-body\"><ul>";
        return $doc;
    }
    /**
     * 按钮
     * @param string $id 唯一id
     * @param string $name 按钮名
     * @param string $href 跳转链接
     * @param int $color 按钮颜色//0绿,1白,2蓝,3黄,4橙,5禁用,6红
     * @param int $size 按钮尺寸//0默认,1迷你，2小型,3大型,4流式
     * @param string $icon 按钮图标
     * @param string $attach 按钮内携带ajax请求的隐藏input
     * @param int $radius 圆角
     * @return string  $doc
     */
    static public function btn($config=[]){
        $default_config = [
            'id'=>'',
            'name'=>'按钮',
            'href'=>false,
            'color'=>0,
            'size'=>0,
            'radius'=>0,//0无圆角 1有圆角
            'icon'=>'',
            'attach'=>'',
        ];
        $config = $config + $default_config;
        $doc = "<a ";
        if($config['href']){
            $doc .="href=\"{$config['href']}\" ";
        }
        else{
            $doc .="href=\"javascript:;\" ";
        }
        $doc .= "class=\"layui-btn ";
        if($config['color']){
            $color = $config['color'];
            if($color==1){$doc .="layui-btn-primary ";}
            if($color==2){$doc .="layui-btn-normal ";}
            if($color==3){$doc .="layui-btn-warm ";}
            if($color==4){$doc .="layui-btn-danger ";}
            if($color==5){$doc .="layui-btn-disabled ";}
            if($color==6){$doc .="layui-btn-red ";}
        }
        if($config['size']){
            $size = $config['size'];
            if($size==1){$doc .="layui-btn-xs ";}
            if($size==2){$doc .="layui-btn-sm ";}
            if($size==3){$doc .="layui-btn-lg ";}
            if($size==4){$doc .="layui-btn-fluid ";}
        }
        if($config['radius']==1){$doc .= "layui-btn-radius ";}
        $doc .= "\">";
        if($config['icon']){
            $doc .="<i class=\"{$config['icon']}\"></i>";
        }
        if($config['attach']){
            $doc .= $config['attach'];
        }
        $doc .="{$config['name']}</a>";
        return $doc;
    }
    /**
     * 带下拉菜单的按钮组
     * @param string $id 唯一id
     * @param string $name 按钮名
     * @param int $color 按钮颜色//0绿,1白,2蓝,3黄,4橙,5禁用,6红
     * @param int $size 按钮尺寸//0默认,1迷你，2小型,3大型,4流式
     * @param string $icon 按钮图标
     * @param array $opt  携带的菜单目录  href||html
     * @return string  $doc
     */
    static public function groupBtn($config=[]){
        $default_config = [
            'id'=>'',
            'name'=>'带下拉菜单的按钮组',
            'color'=>0,
            'size'=>0,
            'icon'=>'',
            'opt'=>['href'=>'','html'=>''],
        ];
        $config = $config + $default_config;
        $color = $config['color'];$size = $config['size'];
        if($size==0){$size="";}
        if($size==1){$size="layui-btn-xs";}
        if($size==2){$size="layui-btn-sm";}
        if($size==3){$size="layui-btn-lg";}
        if($size==4){$size="layui-btn-fluid";}
        if($color==0){$color ="";}
        if($color==1){$color ="layui-btn-primary ";}
        if($color==2){$color ="layui-btn-normal ";}
        if($color==3){$color ="layui-btn-warm ";}
        if($color==4){$color ="layui-btn-danger ";}
        if($color==5){$color ="layui-btn-disabled ";}
        if($color==6){$color ="layui-btn-red ";}
        $li = "";
        if(is_array($config['opt'])){
            foreach($config['opt'] as $k=>$v){
                $li .= "<li><a href=\"{$v['href']}\">{$v['html']}</a></li>";
            }
        }
        $doc ="<div class=\"layui-btn-group btn-group\" id=\"{$config['id']}\">
                    <a href=\"javascript:;\" class=\"layui-btn {$size} {$color}\">
                        <i class=\"{$config['icon']}\" style=\"margin-right: 0\"></i> {$config['name']}
                    </a>
                    <button class=\"layui-btn {$size} {$color}\" style=\"margin-bottom: 0;padding: 0 5px\">
                        <i class=\"layui-icon layui-icon-down\"></i>
                    </button>
                    <div class=\"card\">
                        <ul>
                            {$li}
                        </ul>
                    </div>
                </div>";
        return $doc;
    }
    /**
     * 区域 开合
     * @param string $id 唯一id
     * @param string $title 区域名
     * @return string  $doc
     */
    static public function field($config=[]){
        if($config=='/'){
            return "</div></fieldset>";
        }
        $default_config = [
            'id'=>'',
            'title'=>'区间',
        ];
        $config = $config + $default_config;
        $doc ="
        <fieldset class=\"layui-elem-field\" id=\"{$config['id']}\">
        <legend>{$config['title']}</legend>
        <div class='layui-field-box'>
        ";
        return $doc;
    }
    /**
     * 提交组合按钮
     * @param int $is_table 是否是table下的提交按钮
     * @return string  $doc
     */
    static public function subBtn( $config=[] ){
        $default_config = [
            'filter'=>'*',
            'is_reset'=>0
        ];
        $config = $config + $default_config;
        $doc ="
        <div class=\"layui-form-item subBtn\">
        <div class=\"layui-input-block\">
        <div class='layui-btn-container'>
            <button lay-submit class=\"layui-btn sub-btn layui-btn-normal\"  lay-filter=\"{$config['filter']}\">提交</button>
            <a href=\"javascript:;\" class=\"layui-btn sub-btn btn-back layui-btn-danger\">返回</a>";
        if($config['is_reset']){
            $doc .= "<button type=\"reset\" class=\"layui-btn sub-btn\">重置</button>";
        }
        $doc .="</div></div></div>";
        return $doc;
    }
    /**
     * 输入框
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $verify |隔开  required|phone
     * 验证 required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证）
     * @param string $type 输入框类型
     * @param string $value 初始值
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交名
     * @param string $pla  提示
     * @param string $word  辅助文字 必须inline状态才能用
     * @return string  $doc
     */
    static public function input($config=[]){
        $default_config = [
            'id'=>'',
            'title'=>'输入框',
            'verify'=>'',
            'value'=>'',
            'type'=>'text',
            'display'=>'block',
            'name'=>'input',
            'pla'=>'',
            'word'=>'',
            'elem'=>[]
        ];
        $config = $config + $default_config;
        $doc =
            "<div class=\"layui-form-item\" id=\"{$config['id']}\">
        <label class=\"layui-form-label\">{$config['title']}";
        $verify = $config['verify'];
        $verify = explode('|',$verify);
        $is_need = false;
        foreach ($verify as $v){
            if($v=='required'){
                $is_need = true;
            }
        }
        if($is_need){
            $doc .= "<span style='color: red;font-size: 16px;'>*</span>";
        }
        $doc .="</label>";
        $doc .= "<div class=\"layui-input-{$config['display']}\">";
        $doc .="<input type=\"{$config['type']}\" name=\"{$config['name']}\"  lay-verify=\"{$config['verify']}\"";
        if(!empty($config['elem'])){
            foreach ($config['elem'] as $v){
                $doc .= " {$v['key']}={$v['value']} ";
            }
        }
        $doc .="  placeholder=\"{$config['pla']}\"  value=\"{$config['value']}\"  autocomplete=\"off\" class=\"layui-input\">
                </div>";
        if($config['word']&&$config['display']=='inline'){
            $doc .=" <div class=\"layui-form-mid layui-word-aux\">{$config['word']}</div>";
        }
        $doc .= "</div>";
        return $doc;
    }
    /**
     * 选择框
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $verify |隔开  required|phone
     * 验证 required（必填项）phone（手机号）email（邮箱）url（网址）number（数字）date（日期）identity（身份证）
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交名
     * @param string $value 默认值
     * @param string $word  辅助文字 必须inline状态才能用
     * @param array $opt  select选项内容 二维数组 内层为 "value|html"
     * @return string  $doc
     */
    static public function select($config=[]){
        $default_config = [
            'id'=>'',
            'title'=>'选择框',
            'verify'=>'',
            'display'=>'block',
            'name'=>'select',
            'word'=>'',
            'value'=>'',
            'opt'=>[['value'=>'','html'=>'']]
        ];
        $config = $config + $default_config;
        $doc ="<div class=\"layui-form-item\" id=\"{$config['id']}\">
        <label class=\"layui-form-label\">{$config['title']}</label>
        <div class=\"layui-input-{$config['display']}\">
            <select name=\"{$config['name']}\" lay-verify=\"{$config['verify']}\" data-value=\"{$config['value']}\">
            <option value=\"\"></option>";
        if(is_array($config['opt'])){
            foreach ($config['opt'] as $k=>$v){
                $doc .= "<option value='{$v['value']}'>{$v['html']}</option>";
            }
        }
        $doc .= "</select></div>";
        if($config['word']&&$config['display']=='inline'){
            $doc .=" <div class=\"layui-form-mid layui-word-aux\">{$config['word']}</div>";
        }
        $doc .="</div>";
        return $doc;
    }
    /**
     * 复选框
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交总名(array)
     * @param string $word  辅助文字 必须inline状态才能用
     * @param array $opt  复选框选项内容 二维数组 内层为 "value|html|checked"
     * @return string  $doc
     */
    static public function checkBox($config=[]){
        $default_config = [
            'title'=>'复选框',
            'display'=>'block',
            'name'=>'checkbox',
            'word'=>'',
            'opt'=>[],
            'value'=>''
        ];
        $config = $config + $default_config;
        $doc =
            "<div class=\"layui-form-item\">
         <label class=\"layui-form-label\">{$config['title']}</label>
         <div class=\"layui-input-{$config['display']} dustar-check-box\" id=\"{$config['name']}\" >";
        $doc .= "<div style='display: inline-block'>";
        $doc .= "<input type='hidden' name=\"{$config['name']}\" value='{$config['value']}'>";
        $value = decode($config['value']);
        if(is_array($config['opt'])){
            if($config['value']){
                foreach ($config['opt'] as $k=>$v){
                    foreach ($value as $v1){
                        if($v1['id']==$v['id']){
                            $config['opt'][$k]['checked'] = 1;
                        }
                    }
                }
            }
            foreach ($config['opt'] as $k=>$v){
                $data = encode($v);
                $doc .="<input type=\"checkbox\" lay-filter=\"{$config['name']}\" name='{$config['name']}_arr[{$data}]' title=\"{$v['name']}\" ";
                if(isset($v['checked'])&&$v['checked']){
                    $doc .="checked ";
                }
                $doc .=">";
            }
        }
        $doc .="</div>";
        $doc .="</div>";
        if($config['word']&&$config['display']=='inline'){
            $doc .=" <div class=\"layui-form-mid layui-word-aux\">{$config['word']}</div>";
        }
        $doc .="</div>";
        return $doc;
    }
    /**
     * 开关
     * @param string $id 唯一id
     * @param string $title 标题
     * @param int $is_label 是否单独使用？
     * @param string $display 自适应 block || 行内 inline
     * @param int||bool $checked 是否已选
     * @param string $text  开|关
     * @param string $name 表单提交名
     * @return string  $doc
     */
    static public function onOff($config=[]){
        $default_config = [
            'id'=>'',
            'title'=>'开关',
            'is_label' => 1,
            'checked'=>'',
            'text'=>'开|关',
            'display'=>'block',
            'name'=>'switch',
            'word'=>'',
        ];
        $config = $config + $default_config;
        if($config['is_label']){
            $doc =
                "<div class=\"layui-form-item\" id=\"{$config['id']}\">
               <label class=\"layui-form-label\">{$config['title']}</label>
               <div class=\"layui-input-{$config['display']}\">
               <input  lay-text=\"{$config['text']}\" type=\"checkbox\" name=\"{$config['name']}\" lay-skin=\"switch\" ";
            if($config['checked']){
                $doc .=" checked ";
            }
            $doc .=">";
            $doc .= "<input name=\"{$config['name']}\" type='hidden' ";
            if($config['checked']){
                $doc .="value=1";
            }
            else{
                $doc .="value=0";
            }
            $doc .= "  />";
            $doc .= "</div></div>";
        }
        else{
            $doc = "<input type=\"checkbox\" name=\"{$config['name']}\" lay-skin=\"switch\" ";
            if($config['id']){
                $doc .="id=\"{$config['id']}\" ";
            }
            if($config['checked']){
                $doc .=" checked ";
            }
            $doc .=">";
        }
        return $doc;
    }
    /**
     * 单选框
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交名
     * @param string $value 默认值
     * @param array $opt  单选框选项内容 二维数组 内层为 "value|html"
     * @return string  $doc
     */
    static public function radio($config=[]){
        $default_config = [
            'id'=>'',
            'title'=>'单选框',
            'value'=>'',
            'is_label' => 1,
            'display'=>'block',
            'name'=>'radio',
            'word'=>'',
            'opt'=>[['value'=>'','html'=>'']],

        ];
        $config = $config + $default_config;
        $doc = "
        <div class=\"layui-form-item\" id=\"{$config['id']}\">
        <label class=\"layui-form-label\">{$config['title']}</label>
        <div class=\"layui-input-{$config['display']}\">";
        foreach ($config['opt'] as $k=>$v){
            $doc .= "<input type=\"radio\" lay-filter=\"{$config['name']}\" name=\"{$config['name']}\" value=\"{$v['value']}\" title=\"{$v['html']}\" ";
            if($v['value']==$config['value']){
                $doc .=" checked ";
            }
            $doc .=">";
        }

        $doc .="</div>";
        if($config['word']&&$config['display']=='inline'){
            $doc .=" <div class=\"layui-form-mid layui-word-aux\">{$config['word']}</div>";
        }
        $doc .="</div>";
        return $doc;
    }
    /**
     * 单选框
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交名
     * @param string $pla 空值提示
     * @param string $value
     * @return string  $doc
     */
    static public function textarea($config=[]){
        $default_config = [
            'id'=>'',
            'title'=>'文本域',
            'display'=>'block',
            'name'=>'textarea',
            'pla'=>'',
            'value'=>''
        ];
        $config = $config + $default_config;
        $doc =
            "
        <div class=\"layui-form-item layui-form-text\" id=\"{$config['id']}\">
        <label class=\"layui-form-label\">{$config['title']}</label>
        <div class=\"layui-input-{$config['display']}\">
            <textarea name=\"{$config['name']}\" placeholder=\"{$config['pla']}\" class=\"layui-textarea\">{$config['value']}</textarea>
        </div>
        </div>";
        return $doc;
    }
    /**
     * 时间组件
     * @param string $id 唯一id
     * @param string $title 标题
     * @param string $display 自适应 block || 行内 inline
     * @param string $name 表单提交名
     * @param string $pla 空值提示
     * @param boolean $is_form 是否表单使用
     * @param string $type 类型 year||month||date||time||datetime 年月日时混合
     * @param string $min 可选最小值 一种是写时间 另外一种是-7
     * @param string $max 可选最大值 一种是写时间 另外一种是+7
     * @param string $range 有此属性则变为时间
     * @param string $value 默认值
     * @return string  $doc
     */
    static public function time($config=[]){
        $default_config = [
            'id'=>'',
            'width'=>'',
            'is_form' => true,
            'title'=>'时间插件',
            'display'=>'block',
            'name'=>'time',
            'pla'=>'时间插件',
            'type'=> 'date',
            'min'=>'1900-1-1',
            'max'=>'2099-12-31',
            'range'=>false,
            'value'=>''
        ];
        $config = $config + $default_config;
        $width = "";
        if($config['width']){
            $width = $config['width'] . 'px';
        }
        if($config['is_form']){
            $doc = "<div class=\"layui-form-item\">";
        }
        $doc .="<div class=\"layui-{$config['display']}\">
                <label class=\"layui-form-label\">{$config['title']}</label>
                <div class=\"layui-input-{$config['display']}\" id=\"{$config['id']}\">
                <input type=\"text\"  style=\"width:{$width}\" class=\"layui-input time-component\" 
                 name=\"{$config['name']}\" placeholder=\"{$config['pla']}\" 
                 data-type=\"{$config['type']}\" 
                 data-value=\"{$config['value']}\"
                 data-min=\"{$config['min']}\"
                 data-max=\"{$config['max']}\"
                 data-range=\"{$config['range']}\">
                </div>
                </div>";
        if($config['is_form']){
            $doc .="</div>";
        }
        return $doc;
    }
    /**
     * 百度编辑器
     * @param string $id 唯一id
     * @param string $name 表单提交名
     * @param string $width 宽度 默认占满
     * @param string $height 高度 默认500px
     * @param string $content 内容 默认500px
     */
    static public function editor( $config = []){
        $default_config = [
            'id'=>'Ueditor',
            'title'=>'编辑器',
            'name'=>'editor',
            'width'=>'100%',
            'height'=>'500px',
            'content'=>''
        ];
        $config = $config + $default_config;
        $doc = "<div class=\"layui-form-item\">
            <label class=\"layui-form-label\">{$config['title']}</label>
            <div class=\"layui-input-block\">";
        $doc .= " <textarea name=\"{$config['name']}\" class=\"Ueditor\" id=\"{$config['id']}\"
        style=\"width:{$config['width']};height:{$config['height']};\">{$config['content']}</textarea>";
        $doc .="</div></div>";
        return $doc;
    }
    /**
     * 表单操作
     * @param string $id 唯一id 必填
     * @param bool $tool_open 是否开启默认工具条监听事件
     * @param bool $is_redelete 是否开启删除为递归删除模式
     * @param string $type 类型 common|recycle
     * @param array $operation 自定义操作杆||默认状态不选|common|recycle
     * @param array $is_search 是否需要搜索 ['time'=>'','key_word'=>'']时间|关键字
     * @param array $pri 查看权限 增删改查审批等等
     * @param string $url 公共目录
     * @param string $data_url  数据方法子目录
     * @param string $search_url  搜索方法子目录 一般情况是本页面
     * @param int $is_excel  是否需要表单导出
     * @param array $search  搜索元素以及默认值 后台给出
     * @param array $table_header 表头设置 后台给出
     * @return string  $doc
     */
    static public function autoTable( $config = []){
        $default_config = [
            'id'=>'',
            'tool_open' => true,
            'is_redelete'=>false,
            'type'=>'common',
            'operation'=>[],
            'is_search'=>[],
            'pri'=>['create'=>0,'update'=>0,'read'=>0,'delete'=>0],
            'url'=>'',
            'data_url'=>'',
            'search_url'=>'index',
            'is_excel' => 0,
            'search'=>['time_key'=>'','time_val'=>'','search_key'=>'','search_val'=>''],
            'table_header'=>[
                ['key'=>'','name'=>'','search'=>0,'templet'=>'','width'=>'','align'=>'center'],
            ]
        ];
        $config = $config + $default_config;
        $pri = $config['pri'];
        $doc ="
        <div class=\"table-content\" data-public-url=\"{$config['url']}\" id=\"{$config['id']}\" >
        <div class=\"table-header\">
        <div style=\"float: left\">
            <div class=\"layui-btn-container\">";
        if($pri['create']&&$config['type']=='common'){
            $doc .= "<a href=\"{$config['url']}add\" title='新增' class=\"layui-btn layui-btn-blue layui-btn-sm\">
                     <i class=\"fa fa-plus\" style=\"margin-right: 0\"></i> <span>新增</span>
                    </a>";
        }
        if($pri['delete']&&$config['type']=='common'){
            $doc .= "<a href=\"javascript:;\" title='批量删除' data-id=\"{$config['id']}\" class=\"batch-del layui-btn layui-btn-red layui-btn-sm\">
                     <i class=\"fa fa-trash-o\" style=\"margin-right: 0\"></i> <span>批量删除</span>
                     </a>";
        }
        if($pri['delete']&&$config['type']=='common'){
            $doc .= "<a href=\"javascript:;\" title='回收站' class=\"recycleindex layui-btn layui-btn-danger layui-btn-sm\">
                    <i class=\"fa fa-recycle\" style=\"margin-right: 0\"></i> <span>回收站</span>
                    </a>";
        }
        if($pri['delete']&&$config['type']=='recycle'){
            $doc .="<a href=\"index\" title='返回' class=\"layui-btn layui-btn-info layui-btn-sm\">
                    <i class=\"fa fa-history\" style=\"margin-right: 0\"></i> <span>返回</span>
                   </a>
                   <a href=\"javascript:;\" title='清空回收站' class=\"clear-btn layui-btn layui-btn-danger layui-btn-sm\">
                      <i class=\"fa fa-recycle\" style=\"margin-right: 0\"></i> <span>清空回收站</span>
                   </a>";
        }
        if($config['is_excel']){
            $doc .= "<div class=\"layui-btn-group import-excel btn-group\" title='导出表格'>
                    <a href=\"javascript:;\" class=\"layui-btn layui-btn-sm\">
                        <i class=\"fa fa-download\"
                           style=\"margin-right: 0\"></i> <span>导出表格</span>
                    </a>
                    <button class=\"layui-btn layui-btn-sm\" style=\"margin-bottom: 0;padding: 0 5px\">
                        <i class=\"layui-icon layui-icon-down\" style=\"font-size:12px!important;\"></i>
                    </button>
                    <div class=\"card\">
                        <ul>";

            $doc .= "</ul></div></div>";
        }
        $doc .= "</div></div>";
        $doc .= "<form action=\"{$config['url']}{$config['search_url']}\" ";
        $doc .= "method=\"post\" class=\"table-search layui-form\"  style=\"float: right\">
            <div class=\"search-dom\">";
        if(!empty($config['is_search'])){
            $doc .="<label class=\"layui-form-label search-label\">检索</label>";
            if(isset($config['is_search']['time'])&&$config['is_search']['time']!=''){
                $doc .= "<div class=\"_time layui-inline\" style='margin-right: 5px;'>
                    <div class=\"time-sort layui-inline\">
                        <div class=\"layui-input-inline\" style=\"width: 100px;\">
                            <select name=\"time_key\" data-value=\"{$config['search']['time_key']}\">
                                <option value=\"create_time\">创建时间</option>
                                <option value=\"update_time\">更新时间</option>
                            </select>
                        </div>
                    </div>
                    <div class=\"layui-input-inline\" style=\"width: 190px;\">
                        <input type=\"text\" class=\"layui-input time-component\" name=\"time_val\"
                               placeholder=\"日期范围\" data-type=\"date\" value=\"{$config['search']['time_val']}\"
                               data-range=\"至\">
                    </div>
                </div>";
            }
            if(isset($config['is_search']['key_word'])&&$config['is_search']['key_word']!=''){
                $doc .= "<div class=\"_search layui-inline\" style='margin-right: 5px;'>
                    <div class=\"search-sort layui-inline\">
                        <div class=\"layui-input-inline\" style=\"width: 100px;\">
                            <select name=\"search_key\" data-value=\"{$config['search']['search_key']}\">
                              ";
                foreach($config['table_header'] as $v){
                    if($v['search']){
                        $doc .="<option value=\"{$v['key']}\">{$v['name']}</option>";
                    }
                }
                $doc .= "</select>
                        </div>
                    </div>
                    <div class=\"search-input layui-inline\">
                     <div class=\"layui-input-inline\">
                       <input type=\"text\" name=\"search_val\" value=\"{$config['search']['search_val']}\"
                       placeholder=\"关键字\" autocomplete=\"off\" class=\"layui-input\">
                    </div>
                   </div>
                </div>";
            }
            $doc .='<button  type="submit" lay-filter="table_search" class="layui-inline layui-btn layui-btn-normal layui-btn-sm">搜索</button>';
        }
        $doc .="</div>
        </form>
       <div style=\"clear: both\"></div>
       </div>
       <table class=\"layui-table\"
           lay-data=\"{ height:'',id:'{$config['id']}',cellMinWidth:100,
                     done: function(res, curr, count){auto_iframe(this.id,res);},
                     where:{time_key:'{$config['search']['time_key']}',time_val:'{$config['search']['time_val']}'
                     ,search_key:'{$config['search']['search_key']}',search_val:'{$config['search']['search_val']}'}
                     ,url:'{$config['url']}/{$config['data_url']}',method:'post'
                     ,page:true}\">
        <thead>
        <tr><th lay-data=\"{type:'checkbox',fixed: 'left'}\"></th>";
        foreach ($config['table_header'] as $v){
            if(isset($v['templet'])&&$v['templet']!=''){
                $elem="";
                if(isset($v['width'])){
                    $elem = "width:{$v['width']}";
                }
                $doc .= "<th lay-data=\"{field:'{$v['key']}',templet:function(d){ return {$v['templet']}}
                    ,sort: true,align:'center',$elem}\">{$v['name']}</th>";
            }
            else{
                $elem="";
                if(isset($v['width'])){
                    $elem = "width:{$v['width']}";
                }
                $align = "align:'center'";
                if(isset($v['align'])){
                    $align = "align:'{$v['align']}'";
                }

                $doc .="<th lay-data=\"{field:'{$v['key']}',sort:true,$align,$elem}\">{$v['name']}</th>";
            }
        }
        if( $config['pri']['create']==0&&
            $config['pri']['update']==0&&
            $config['pri']['read']==0&&
            $config['pri']['delete']==0
        ){

        }
        else{
            $doc .= "<th lay-data=\"{title:'操作',minWidth:165,'fixed':'right',align:'center',toolbar:'.operation'}\"></th>";
        }
        $doc .="</tr>
        </thead>
    </table>
       </div>";
        if($config['type']=='common'&&empty($config['operation'])){
            $add = "";$edit = "";$del = "";
            if($pri['read']){
                $add = " 
                <a title='详情' class=\"layui-btn  layui-btn-info operation-btn layui-btn-xs detail\" lay-event=\"detail\">
                <i class=\"fa fa-folder\" style=\"margin-right:-1px\"></i>
                <span>详情</span>
                </a>";
            }
            if($pri['update']){
                $edit = "
                <a title='编辑' style=\"margin-left: 0;\" class=\"layui-btn layui-btn-success operation-btn layui-btn-xs edit\" lay-event=\"edit\">
                <i class=\"fa fa-edit\" style=\"margin-right:-1px;margin-top: 1px\"></i>
                <span>编辑</span>
                </a>";
            }
            if($pri['delete']){
                $delClass = "delete";
                if($config['is_redelete']){
                    $delClass = "redelete";
                }
                $del = "
                 <a style=\"margin-left: 0;\" title='删除' class=\"layui-btn layui-btn-red operation-btn
                layui-btn-xs {$delClass}\" lay-event=\"{$delClass}\">
                 <i class=\"fa fa-trash-o\" style=\"margin-right:-1px\"></i>
                 <span>删除</span>
                 </a>
                ";
            }
            $doc .= "
        <script type=\"text/html\" class=\"operation\">
        {$add}
        {$edit} 
        {$del}
        </script>";
        }
        if($config['type']=='recycle'&&empty($config['operation'])){
            if($pri['delete']){
                $list = " 
                <a style=\"margin-left: 0;\" title='还原' class=\"layui-btn layui-btn-warm operation-btn layui-btn-xs reduction\" lay-event=\"reduction\">
                <i class=\"fa fa-edit\" style=\"margin-right:-1px;margin-top: 1px\"></i>
                <span>还原</span>
                </a>
                <a style=\"margin-left: 0;\" title='销毁' class=\"layui-btn layui-btn-red operation-btn layui-btn-xs cleanUp\" lay-event=\"cleanUp\">
                <i class=\"fa fa-trash-o\" style=\"margin-right:-1px\"></i>
                <span>销毁</span>
                </a>";
            }
            $doc .= "
            <script type=\"text/html\" class=\"operation\">
              {$list}
            </script>";
        }
        if(!empty($config['operation'])){
            $type = $config['operation'];
            $list = "";
            foreach ($type as $k=>$v){
                if(isset($v['color'])){$color = $v['color'];}
                else{$color = '';}
                if(isset($v['icon'])){$icon = $v['icon'];}
                else{$icon = "fa fa-circle-o";}
                if($pri[$v['pri']]){
                    $list .="<a title=\"{$v['name']}\" class=\"layui-btn {$color} operation-btn layui-btn-xs {$v['event']}\" lay-event=\"{$v['event']}\">
                    <i class=\"{$icon}\" style=\"margin-right:-1px\"></i>
                    <span>{$v['name']}</span>
                    </a>";
                }
            }
            $doc .=
                "<script type=\"text/html\" class=\"operation\">
             {$list}
            </script>";
        }
        if($config['tool_open']){
            $doc .="
            <script>
            $(function() {
                layui.use(['table'],function () {
                table.on('tool', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter=\"对应的值\"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var content = $(this).parents('.table-content');
                var public_url = content.data('public-url');
                var url = public_url + layEvent + '?id=' + data.id;
                if(layEvent=='delete'){
                    parent.parent.layer.confirm('是否删除？',function(index){
                        $.ajax({
                            url:url,
                            dataType:'json',
                            success:function (res) {
                                parent.parent.layer.msg(res.msg);
                                if(res.code==1){
                                    window.location.reload();
                                }
                                console.log(res);
                            }
                        });
                        parent.parent.layer.close(index);
                    });
                }else
                if(layEvent=='cleanUp'){
                    parent.parent.layer.confirm('销毁后将无法还原，确认销毁吗？',function (index) {
                        $.ajax({
                            url:url,
                            dataType:'json',
                            success:function (res) {
                                parent.parent.layer.msg(res.msg);
                                if(res.code==1){
                                    window.location.reload();
                                }
                            }
                        });
                        parent.parent.layer.close(index);
                    })
                }else
                if(layEvent=='reduction'){
                    parent.parent.layer.confirm('是否还原？',function (index) {
                        $.ajax({
                            url:url,
                            dataType:'json',
                            success:function (res) {
                                parent.parent.layer.msg(res.msg);
                                if(res.code==1){
                                    window.location.reload();
                                }
                            }
                        });
                        parent.parent.layer.close(index);
                    });
                }else
                if(layEvent=='redelete'){
                     parent.parent.layer.confirm('将递归删除该条记录下的子记录，是否执行？',function(index){
                        $.ajax({
                            url:url,
                            dataType:'json',
                            success:function (res) {
                                parent.parent.layer.msg(res.msg);
                                if(res.code==1){
                                    window.location.reload();
                                }
                                console.log(res);
                            }
                        });
                        parent.parent.layer.close(index);
                    });
                }else 
                { window.location.href = url;}
            });
                });
               $('.table-content').each(function () {
         var public_url = $(this).data('public-url');
         var id = $(this).attr('id');
         $(this).find('.batch-del').click(function () {
            parent.parent.layer.confirm('是否删除？',function(index){
                var checkStatus = table.checkStatus(id)
                    ,data = checkStatus.data;
                var idArr = [];
                for (var i=0;i<data.length;i++){
                    idArr.push(data[i].id);
                }
                idArr = idArr.join(',');
                console.log(idArr);
                $.ajax({
                    url:public_url + 'delete',
                    dataType:'json',
                    data:{'id':idArr},
                    success:function (res) {
                        parent.parent.layer.msg(res.msg);
                        if(res.code==1){
                            window.location.reload();
                        }
                    }
                });
                parent.parent.layer.close(index);
            });
        });
         $(this).find('.recycleindex').click(function () {
            window.location.href = public_url + 'recycleindex';
        });
         $(this).find('.clear-btn').click(function () {
            parent.parent.layer.confirm('清空后将无法还原数据，确认清空吗？',function(index){
                $.ajax({
                    url:public_url + 'cleanUp',
                    dataType:'json',
                    data:{'id':'all'},
                    success:function ( res ) {
                        parent.parent.layer.msg(res.msg);
                        if(res.code==1){
                            window.location.href = 'index';
                        }
                    }
                })
            });
        });
       });
            })
            </script>
            ";
        }
        return $doc;
    }
    /**
     * 图片上传插件 闭合
     * @param string $id  唯一标识
     * @param string $arr 默认图片
     * @param string $title 图片上传标题
     * @param int $max  上传图片的最大数量
     * @param int $mw  上传图片的最大宽度
     * @param int $mh  上传图片的最大高度
     * @param int $w  div宽度
     * @param string  返回字符串
     */
    static public function imgUpload($config = []){
        $default_config = [
            'id'=>'img_upload',
            'arr'=>'',
            'title'=>'',
            'max'=> 1,
            'mw'=>3000,
            'mh'=>3000,
            'w'=>'100'
        ];
        $config = $config + $default_config;
        $doc ="
        <div class=\"layui-form-item\" id=\"\">
        <label class=\"layui-form-label\">{$config['title']}</label>
        <div class=\"layui-input-block\">
        ";
        $doc .=
            "<div id=\"{$config['id']}\" 
             class=\"img-upload\" style=\"width:{$config['w']}%;margin: 0 auto\"  
             data-arr=\"{$config['arr']}\"  
             data-max=\"{$config['max']}\"
             data-mw=\"{$config['mw']}\" data-mh=\"{$config['mh']}\"></div>
            ";
        $doc .="
        </div></div> 
        ";
        return $doc;
    }
    /*
     * ajax请求组件
     * @param int $id  唯一id
     * @param int $effect  是否立即执行 1|0 是|否
     * @param array $params  需要携带参数
     * @param string $url   请求地址
     * @param string $pop   当返回的code为1|0时是否弹窗 yes|1时弹 no|0时弹
     * @param string $type   get|post|put|delete
     * @param bool $jump_url true 跳转完整url  false 跳转相对路径
     * @return string  $doc
     */
    static public function ajax( $config = [] ){
        $default_config = [
            'id'=>'',
            'effect' => 0,
            'params' => false,
            'url' => '',
            'pop' => 'yes,no',
            'type'=> 'get',
            'jump_url'=>false
        ];
        $config = $config + $default_config;
        $params = encode( $config['params'] );
        $doc = "";
        $doc .= "<input id=\"{$config['id']}\" type=\"hidden\" class=\"ajax-btn\" data-effect=\"{$config['effect']}\"";
        if($config['params']){
            $doc .= " data-params=$params ";
        }
        if($config['jump_url']){
            $doc .= " data-jump_url={$config['jump_url']} ";
        }
        $doc .= " data-url=\"{$config['url']}\"
                  data-type=\"{$config['type']}\"
                  data-pop=\"{$config['pop']}\" ";
        $doc .= "/>";
        return $doc;
    }
    /**
     * 二维码生成 闭合
     * @param string $href  二维码链接
     * @param string $render 渲染方式 canvas|table
     * @param string $bac 背景色
     * @param string $fore  前景色
     * @param int $width  宽度
     * @param int $height  高度
     * @param string  返回字符串
     */
    static public function qrcode($config = []){
        $default_config =[
            'href'=>'',
            'render'=>'canvas',
            'bac'=>'#fff',
            'fore'=>'#000',
            'width'=>'150',
            'height'=>"150"
        ];
        $config = $config + $default_config;
        $doc = " <div style='display: inline-block' class=\"qrcode\" data-href=\"{$config['href']}\"
        data-render=\"{$config['render']}\" data-bac=\"{$config['bac']}\" data-fore=\"{$config['fore']}\"
        data-width=\"{$config['width']}\" data-height=\"{$config['height']}\"></div>";
        return $doc;
    }
    /**
     * 复制按钮 闭合
     * @param string $text  要复制的内容
     * @param string $html 按钮文案
     * @param string $size 尺寸
     * @param string $color 颜色
     * @param string  返回字符串
     */
    static public function copyBtn($config = []){
        $default_config =[
            'text'=>'',
            'html'=>'复制',
            'style'=>''
        ];
        $config = $config + $default_config;
        $doc = "<button class='layui-btn {$config['style']} copy-btn'
                data-clipboard-text=\"{$config['text']}\" >{$config['html']}</button>";
        return $doc;
    }
    /**
     * 截图按钮 闭合
     * @param string $text  要复制的内容
     * @param string $html 按钮文案
     * @param string $size 尺寸
     * @param string $color 颜色
     * @param string  返回字符串
     */
    static public function screenShot($config = []){
        $default_config =[
            'html'=>'按钮',
            'dom'=>'',
            'filename'=>'文件名',
            'style'=>''
        ];
        $config = $config + $default_config;
        $doc = "<button class=\"layui-btn screen-shot {$config['style']}\" data-html=\"{$config['html']}\"
        data-file-name=\"{$config['filename']}\" data-dom=\"{$config['dom']}\">
        {$config['html']}</button>";
        return $doc;
    }
    /**
     * 大文件上传 闭合
     * @param string $id  唯一ID 必填
     * @param string $title 标题
     * @param string $accept  目前支持 *||images
     * @param string $filenum 文件数量
     * @param string $maxsize 可上传的最大文件
     * @param string $value  默认已上传的文件
     * @param string  返回字符串
     */
    static public function largeUpload($config = []){
        $default_config =[
            'id'=>'upload',
            'title'=>'大文件上传',
            'accept'=>'*',
            'filenum'=>1,
            'maxsize'=>'10240000',
            'value'=>[],
        ];
        $config = $config + $default_config;
        $SystemConfig = config('SystemConfig');
        $box = "";
        if($config['value']){
            foreach ($config['value'] as $k=>$v){
                $public_url  = $v['url'];
                $url = $SystemConfig['App'] . $v['url'];
                if($v['accept']=='images'){
                    $thumb_img = $url;
                }
                else{
                    $thumb_img = $SystemConfig['App'] . "/public/static/common/img/img_upload/fileIcon.png";
                }
                $size = $v['size']/1024;$size = round($size,0);
                $box .= "
         <div id=\"{$v['id']}\" data-url=\"{$public_url}\" data-md5=\"{$v['md5']}\" class=\"box-container 
        layui-col-xs12 layui-col-sm4 layui-col-md3\">
        <div class=\"box\"><div class=\"shadow\" style=\"display: none;\">
        <span>文件校验中(100%)</span></div>
        <a href=\"{$url}\" 
        class=\"down\" download=\"{$v['filename']}\">
        <div class=\"file-priview\">
        <img title=\"{$v['filename']}\"
         src=\"{$thumb_img}\" alt=\"\"></div></a><a class=\"title down\" 
         download=\"{$v['filename']}\" 
         title=\"{$v['filename']}\" 
         href=\"{$url}\" target=\"_blank\">{$v['filename']}</a>
         <div class=\"file-size\">{$size}KB</div><div class=\"layui-progress layui-progress-big\">
         <div class=\"layui-progress-bar layui-bg-blue\" lay-percent=\"100%\"><span>100%</span></div></div>
         <div class=\"bottom\"><div class=\"btn-right\"><button type=\"button\"
          class=\"layui-btn layui-btn-xs re-upload\"><i class=\"fa fa-upload\"></i>
          <span>重传</span></button><button type=\"button\" class=\"layui-btn layui-btn-xs 
          layui-btn-red upload-delete\"><i class=\"fa fa-trash-o\"></i> 
          <span>删除</span></button></div></div></div></div>
        ";
            }
        }
        $doc =
            "
         <div class=\"layui-form-item\">
        <label class=\"layui-form-label\">{$config['title']}</label>
        <div class=\"layui-input-block\">
            <div class=\"large-file-upload\" data-filenum=\"{$config['filenum']}\" 
            data-accept=\"{$config['accept']}\" data-id=\"{$config['id']}\" data-maxsize=\"{$config['maxsize']}\">
                <input type=\"hidden\" name=\"{$config['id']}\" value=\"\">
                <div class=\"upload-file\" id=\"{$config['id']}\">选择文件</div>
                <div class=\"layui-btn-container\">
                    <button type=\"button\"  class=\"upload-head-btn layui-btn layui-btn-sm upload-btn\">
                        <i class=\"fa fa-upload\"></i>
                        <span>上传</span>
                    </button>
                    <button type=\"button\" class=\"upload-head-btn layui-btn layui-btn-sm layui-btn-warm pause-btn\">
                        <i class=\"fa fa-pause\"></i>
                        <span>暂停</span>
                    </button>
                </div>
                <div style=\"color: #999\">请上传<span style=\"color: red\">{$config['filenum']}</span>个小于<span style=\"color: red\">{$config['maxsize']}KB</span>的文件</div>
                <div style=\"clear: both\"></div>
                <div class=\"layui-row layui-col-space15 container\" style=\"min-height: 279px;\">
                 {$box}
                </div>
                <div style=\"clear: both\"></div>
            </div>
        </div>
    </div>
        ";
        return $doc;
    }

    /**
     * 模块配置文件模板 无参数 闭合
     */
    static public function moduleConfig(){
    $doc =
    "<?php
     return[
     /**
     * 控制器通用配置
     * 只有validate这个是 两个都验证、且Common验证通过后验证子类。
     * 其他的配置均为子类覆盖common，common覆盖内置默认配置。（action>controller>module）;
     * 权限转移:common 加一个pri  可关联到使用其他控制器的权限。
     */
    'common'=>[
        'method'=> ['GET', 'POST', 'PUT', 'DELETE'],
        'is_cross'=>0,
        'is_login'=>'session',
        //'table'=>'empty',
        //'pri'=>'',
    ],
    'index'=>[
        'is_login'=>0
    ],
    'is_login'=>[
        'is_login'=>0
    ]
    ];
    ";
    return $doc;
    }
    /**
     * 生成控制器文件 闭合
     * @param string $name  控制器名
     * @param string $module 所属模块名
     * @param int|bool $is_index 是否生成首页index方法
     * @param array $use 用到的组件和模块
     * @param string $extends 集成对象 默认Common
     * @param array $action 自定义方法
     * @param string  返回字符串
     */
    static public function makeController( $config = [] ){
        $default_config =[
            'name'=>'Rename',
            'module'=>'rename',
            'is_index'=>1,
            'use'=>[],
            'extends'=>'Common',
            'action'=>[],
        ];
        $config = $config + $default_config;
        $classname = ucfirst( $config['name']);
        $spacemodule = lcfirst($config['module']);

        $doc =
        '<?php';
        $doc .="\n";
        $doc .=
        'namespace app\\' .$spacemodule .'\controller;';
        if($config['use']&&is_array($config['use'])){
            $doc .="\n";
            foreach ($config['use'] as $k=>$v){
                $doc .= $v; $doc .="\n";
            }
        }
        $doc .="\n";
        $doc .=
        'class '.$classname.' extends ' . ucfirst( $config['extends'] ) .' {';
        $doc .="\n";
        if($config['is_index']){
        $doc .= '
        public function index(){
          return $this->fetch();
        }';
        }
        if($config['action']&&is_array($config['action'])){
            $doc .="\n";
            foreach ($config['action'] as $k=>$v){
                $doc .= $v; $doc .="\n";
            }
        }
        $doc .="\n";
        $doc .='}';
        return $doc;
    }


    static public function moduleLayout(){
        $doc =
'{include file="../application/tpl/iframe_tpl/header.html"/}
{__CONTENT__}
{include file="../application/tpl/iframe_tpl/footer.html"/}        
';
        return $doc;
    }

    static public function menuConfig(){

    }

}